package com.jie.deletefile.xutilIamge;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.jie.deletefile.Imgeview.VpActivity;
import com.jie.deletefile.R;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class ImageActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private android.widget.ListView lvutils;
    private android.widget.RelativeLayout activityimage;
    private List<String> data;
    private MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image);
        this.activityimage = (RelativeLayout) findViewById(R.id.activity_image);
        this.lvutils = (ListView) findViewById(R.id.lv_utils);
        data = new ArrayList<>();
        data.add("http://7xsct4.com1.z0.glb.clouddn.com/16-9-21/44621585.jpg");
        data.add("http://7xsct4.com1.z0.glb.clouddn.com/16-9-21/41331577.jpg");
        data.add("http://7xsct4.com1.z0.glb.clouddn.com/16-9-21/98887668.jpg");
        data.add("http://7xsct4.com1.z0.glb.clouddn.com/16-9-21/14976634.jpg");
        data.add("http://7xsct4.com1.z0.glb.clouddn.com/16-9-21/65897578.jpg");
        adapter = new MyAdapter();
        lvutils.setAdapter(adapter);

        lvutils.setOnItemClickListener(this);

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(ImageActivity.this, VpActivity.class);
        intent.putExtra("position", position);
        startActivity(intent);
    }


    class MyAdapter extends BaseAdapter {


        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(ImageActivity.this).inflate(R.layout.item_xtuil, null);
            }
            ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_itemx);
            x.image().bind(imageView,data.get(position));
            return convertView;
        }
    }
}

